package com.hermeneute.fsa;

import java.util.Comparator;

class FSTEvent {
    char input;
    char output;
    static char Epsilon = 1;
    static char Any = 2;
    
    char getIn(){
	return input;
    }

    void setIn(char v){
	input = v;
    }
    
    char getOut(){
	return output;
    }
    
    void setOut(char v){
	output = v;
    }
    
    void print()
    {
	System.out.println ((char)getIn()+":"+(char)getOut());
    }
    
    boolean isNull() {
	return (input == 0) && (output == 0);
    } 
    
    public boolean equals ( FSTEvent e) {
	return ((getIn() == e.getIn ())&&(getOut() == e.getOut ()));
    }
    boolean ne ( FSTEvent e) {
	return ((getIn() != e.getIn ())||(getOut() != e.getOut ()));
    }

    boolean lt ( FSTEvent e) {
	if ((getIn() < e.getIn ())||((getIn() == e.getIn ())&& (getOut() < e.getOut ()))) {
	    return true;
	} else 
	    return false;
    }
    
    
    boolean isCut()      { return ((input == 0)&&(output == 6)); }
    boolean isFail() 	{ return ((input == 0)&&(output == 7)); }
    boolean isAnyX() 	{ return ((input == Any)&&(output != Any)); }
    boolean isXAny() 	{ return ((input != Any)&&(output == Any)); }
    boolean isAnyAny() 	{ return ((input == Any)&&(output == Any)); }
    
    FSTEvent(){
	input = 0;
	output = 0;
    }
    FSTEvent(char v1, char v2){
	input = v1;
	output = v2;
    }

    public boolean equals (Object e) { 
	return 
	    (getOut() == ((FSTEvent)e).getOut()) && 
	    (getIn() == ((FSTEvent)e).getIn()); 
    }
    int compareTo (FSTEvent event)
    {
	if (event.equals(this)){
	    return 0;
	}else if (event.lt(this)){
	    return -1;
	}else
	    return 1;
    }

    public int hashCode() {
	return (int)getOut()+(int)getIn();
    }
}

class FSTEventComparator implements Comparator {
    public int compare(Object o1, Object o2) {
	return ((FSTEvent)o1).compareTo((FSTEvent)o2);
    }
}
